#include "TcpServer.hpp"

TcpServer::TcpServer(const string & ip, unsigned short port)
: _acceptor(ip, port)
, _loop(_acceptor)
{}

TcpServer::~TcpServer(){
    // do nothing
}

// 服务器启动与停止
void TcpServer::start(){
    _acceptor.ready();
    _loop.loop();
}

void TcpServer::stop(){
    _loop.unloop();
}

// 设置三个回调函数: 分别设置NewConnectionCallback，MessageCallback，CloseCallback
void TcpServer::setAllCallback(Callback &&cb1, Callback &&cb2, Callback &&cb3){
    _loop.setNewConnectionCallback(std::move(cb1));
    _loop.setMessageCallback(std::move(cb2));
    _loop.setCloseCallback(std::move(cb3));
}